//
//  KCVisitorStoreCell.swift
//  MyKC
//
//  Created by yy on 2017/3/21.
//  Copyright © 2017年 com.yasuo. All rights reserved.
//
import UIKit
@objc protocol VisitorStoreCellDelegate: NSObjectProtocol {
    @objc optional func btnDidClick(model: KCPlanModel?)
}
class KCVisitorStoreCell: UITableViewCell {
    weak var delegate:VisitorStoreCellDelegate?
    var model: KCPlanModel? {
        //外界已经完成了的赋值
        didSet {
           lbe_storeName.text = model?.StoreName
           lbe_storeCode.text = model?.StoreNo
            if model?.TaskStatus == NotStart {
                if model?.TaskType == "940" {
                    btn_visitor.setTitle("未拜访", for: .normal)
                }else {
                    btn_visitor.setTitle("未开始", for: .normal)
                }
                btn_visitor.layer.borderColor = colorRGB(r: 54, g: 160, b: 249).cgColor
                btn_visitor.isHidden = false
                btn_finishImage.isHidden = true
                btn_visitor.backgroundColor = UIColor.white
            }
            if model?.TaskStatus == Visiting {
                btn_visitor.setTitle("拜访中", for: .normal)
                btn_visitor.setTitleColor(UIColor.white, for: .normal)
                btn_visitor.layer.borderColor = colorRGB(r: 225, g: 86, b: 151).cgColor
                btn_visitor.isHidden = false
                btn_finishImage.isHidden = true
//                btn_visitor.tintColor = colorRGB(r: 252, g: 86, b: 103)
                btn_visitor.backgroundColor = colorRGB(r: 252, g: 86, b: 103)
            }
            if model?.TaskStatus == HasEnded {
                btn_visitor.isHidden = true
                btn_finishImage.isHidden = false
            }
            if model?.TaskStatus == Expired {
                btn_visitor.isHidden = false
                btn_finishImage.isHidden = true
                btn_visitor.layer.borderColor = UIColor.white.cgColor
                btn_visitor.setTitle("已过期", for: .normal)
                btn_visitor.setTitleColor(UIColor.white, for: .normal)
                btn_visitor.backgroundColor = UIColor.lightGray
            }
        }
    }
    @IBOutlet weak var lbe_storeName: UILabel!
    @IBOutlet weak var lbe_storeCode: UILabel!
    @IBOutlet weak var btn_visitor: UIButton!
    @IBOutlet weak var btn_finishImage: UIButton!
    @objc private func btnClick(sender:UIButton) {
        delegate?.btnDidClick?(model: model)
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        btn_visitor.layer.borderWidth = 1
        btn_visitor.layer.borderColor = colorRGB(r: 54, g: 160, b: 249).cgColor
        btn_visitor.layer.cornerRadius = 5
        btn_visitor.clipsToBounds = true
        btn_finishImage.isHidden = true
        btn_visitor.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
        btn_finishImage.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
    }
}
